﻿Imports System.Data.OleDb
Public Class frmStaffManager

#Region "NotifyIcon"

    Private Sub frmStaffManager_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        Try
            If Me.WindowState = FormWindowState.Minimized Then
                Me.Visible = False
                NotifyIcon.Visible = True
                NotifyIcon.ShowBalloonTip(1, "SkyCoffee", "SkyCoffee is Still Running!", ToolTipIcon.Info)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub NotifyIcon_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon.MouseDoubleClick
        Try
            Me.Visible = True
            Me.WindowState = FormWindowState.Normal
            NotifyIcon.Visible = False
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub mnuLaunchApplication_Click(sender As Object, e As EventArgs) Handles mnuLaunchApplication.Click
        Try
            Me.Visible = True
            Me.WindowState = FormWindowState.Normal
            NotifyIcon.Visible = False
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub mnuExitApplication_Click(sender As Object, e As EventArgs) Handles mnuExitApplication.Click
        Application.Exit()
    End Sub
#End Region

    Private Sub frmStaffManager_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Loads frmMenu
        pnlIcons.Controls.Clear()
        pnlIcons.Controls.Add(frmMenu.pnlIcons)

        'Loads frmStaffMenu
        pnlIconsStaff.Controls.Clear()
        pnlIconsStaff.Controls.Add(frmStaffMenu.pnlIconsStaff)

        'Load ToolTips
        AdminToolTips()
        StaffToolTips()

        'Clears ListView before it is populated to avoid duplicate records
        lstDisplayStaff.Items.Clear()

        'Populates ListView from Access Database
        Try
            PopulateStaffListFromAccess(lstDisplayStaff)
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub

    Private Sub tsbtnAdd_Click(sender As Object, e As EventArgs) Handles tsbtnAdd.Click
        frmManageStaff.Show()
        frmManageStaff.AddNewRecord()
        Me.Close()
    End Sub

    Private Sub tsbtnEdit_Click(sender As Object, e As EventArgs) Handles tsbtnEdit.Click
        frmManageStaff.Show()
        Me.Close()
    End Sub

    Private Sub tsbtnDelete_Click(sender As Object, e As EventArgs) Handles tsbtnDelete.Click
        frmManageStaff.Show()
        Me.Close()
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If txtSearchReferenceNumber.Text IsNot "" And lstDisplayStaff.Items.Count > 0 Then
            lstDisplayStaff.Focus()

            For i = 0 To lstDisplayStaff.Items.Count - 1
                'Searches second column: SubItems(0)
                If lstDisplayStaff.Items(i).SubItems(0).Text = txtSearchReferenceNumber.Text Then
                    lstDisplayStaff.Items(i).Selected = True
                End If
                MsgBox("Search Completed Successfully")
            Next

        ElseIf txtSearchFirstName.Text IsNot "" And lstDisplayStaff.Items.Count > 0 Then
            lstDisplayStaff.Focus()

            For i = 0 To lstDisplayStaff.Items.Count - 1
                'Searches third column: SubItems(1)
                If lstDisplayStaff.Items(i).SubItems(1).Text = txtSearchFirstName.Text Then
                    lstDisplayStaff.Items(i).Selected = True
                End If
                MsgBox("Search Completed Successfully")
            Next

        ElseIf txtSearchSurname.Text IsNot "" And lstDisplayStaff.Items.Count > 0 Then
            lstDisplayStaff.Focus()

            For i = 0 To lstDisplayStaff.Items.Count - 1
                'Searches fourth column: SubItems(2)
                If lstDisplayStaff.Items(i).SubItems(2).Text = txtSearchSurname.Text Then
                    lstDisplayStaff.Items(i).Selected = True
                End If
                MsgBox("Search Completed Successfully")
            Next

        ElseIf txtSearchReferenceNumber.Text = "" Or txtSearchFirstName.Text = "" Or txtSearchSurname.Text = "" Then
            MsgBox("Please enter some text to initiate a search.")
        End If
    End Sub

    Private Sub btnSearchClear_Click(sender As Object, e As EventArgs) Handles btnSearchClear.Click
        'Empty Search form
        txtSearchReferenceNumber.Text = ""
        txtSearchFirstName.Text = ""
        txtSearchSurname.Text = ""

        txtSearchReferenceNumber.Focus()
    End Sub

    Private Sub tsbtnSendEmail_Click(sender As Object, e As EventArgs) Handles tsbtnSendEmail.Click
        frmSendEmail.Show()
        Me.Close()
    End Sub

    Private Sub tsbtnSendSMS_Click(sender As Object, e As EventArgs) Handles tsbtnSendSMS.Click
        frmSendSMS.Show()
        Me.Close()
    End Sub
End Class